package com.mygdx.game;

import com.badlogic.gdx.Game;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.OrthographicCamera;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.physics.box2d.Body;
import com.badlogic.gdx.physics.box2d.BodyDef;
import com.badlogic.gdx.physics.box2d.Box2DDebugRenderer;
import com.badlogic.gdx.physics.box2d.EdgeShape;
import com.badlogic.gdx.physics.box2d.FixtureDef;
import com.badlogic.gdx.physics.box2d.World;
import com.sun.prism.image.ViewPort;

/**
 * Created by zhimi on 2016/8/5.
 */
public class Box2DTest extends Game {

    SpriteBatch batch;

    Box2DDebugRenderer renderer;

    World world;

    Vector2 vector2;

    private OrthographicCamera camera;

    @Override
    public void create() {
        renderer = new Box2DDebugRenderer();
        batch = new SpriteBatch();
        vector2 = new Vector2(0, 0);

        world = new World(vector2, true);
        EdgeShape edgeShape = new EdgeShape();
        FixtureDef fixtureDef = new FixtureDef();
        fixtureDef.shape = edgeShape;
        edgeShape.set(new Vector2(0, 0), new Vector2(48f, 0));

        BodyDef bodyDef = new BodyDef();
        bodyDef.position.set(2, 2);
        Body groupBody = world.createBody(bodyDef);

        groupBody.createFixture(fixtureDef);
        camera = new OrthographicCamera(80, 48);
    }

    @Override
    public void render() {
//        Gdx.gl.glClearColor(1, 1, 1, 1);
        Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
        world.step(Gdx.app.getGraphics().getDeltaTime(), 6, 2);

        camera.update();
        renderer.render(world, camera.combined);
//        batch.begin();
        //batch.draw(ball, body.getPosition().x, body.getPosition().y, 5f, 5f);
//        batch.end();
    }
}
